Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(clustering/rpc): rpc mock/hook #14030

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

tests(clustering/rpc): rpc mock/hook #14030

wants to merge 1 commit into from

Conversation

StarlightIbuki
Copy link
Contributor

Summary

RPC needs mock tests

Checklist

  • The Pull Request has tests
  • A changelog file has been created under changelog/unreleased/kong or skip-changelog label added on PR if changelog is unnecessary. README.md

Issue reference

Fix KAG-5551

@github-actions github-actions bot added the cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee label Dec 17, 2024
@chronolaw chronolaw self-requested a review December 18, 2024 07:30
@chronolaw chronolaw changed the title tests(rpc): rpc mock/hook tests(clustering/rpc): rpc mock/hook Dec 18, 2024
@StarlightIbuki StarlightIbuki force-pushed the rpc-mock branch 2 times, most recently from c79e2be to 5438bcc Compare December 18, 2024 07:57
config = {},
})

assert(helpers.start_kong(self))
Copy link
Contributor

@chobits chobits Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start a mock cp to proxy client's rpc request to DP


assert(helpers.start_kong(self))

self.proxy_client = client.new({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client -> mock cp --> tested DP

self:enable_inception()
end

self.proxy_client.callbacks:register("kong.rpc.proxy.mock", function(proxy_id, proxy_payload)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mock cp will rpc call this callback to forward [the RPC call request from tested DP] to [client]

server_mock = server.new()
assert(server_mock:start())

assert(helpers.start_kong({
Copy link
Contributor

@chobits chobits Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add a comment to explain this is.a tested DP

spec/02-integration/01-helpers/05-rpc-mock_spec.lua Outdated Show resolved Hide resolved
spec/01-unit/19-hybrid/04-rpc_spec.lua Outdated Show resolved Hide resolved
spec/01-unit/19-hybrid/04-rpc_spec.lua Outdated Show resolved Hide resolved
spec/02-integration/01-helpers/05-rpc-mock_spec.lua Outdated Show resolved Hide resolved
spec/01-unit/19-hybrid/04-rpc_spec.lua Outdated Show resolved Hide resolved
spec/helpers/rpc_mock/client.lua Outdated Show resolved Hide resolved
Comment on lines +73 to +76
local prehook = self.prehooks[method] or self.prehooks["*"]
local posthook = self.posthooks[method] or self.posthooks["*"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need add some comment for prehook and post hook

local helpers = require("spec.helpers")
local client = require("spec.helpers.rpc_mock.client")
local default_cert = require("spec.helpers.rpc_mock.default").default_cert

Copy link
Contributor

@chobits chobits Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly recommend you to write a callback and diagram in the comment like, or you could write a design doc

-- Diagram:
-- 
-- mock client -> mock server -> tested DP
-- 
-- Callback chains:
--
-- func1
--  -> func2
--   -> func3 ...

otherwise other developers or reviewers find it hard to understand, today i talked with @chronolaw , he found it hard to understand what the server.lua does here.

Copy link
Contributor

@chobits chobits Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a good way is that you could write a test case to run this mock client -> mock server -> tested DP progress, i find there is no case for mock server<>tested DP. Then we could explain the progress with that case, that might be easy to understand for reviewers.

@StarlightIbuki StarlightIbuki force-pushed the rpc-mock branch 5 times, most recently from d006c6f to 311cf69 Compare December 23, 2024 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee core/clustering size/XL skip-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants